﻿#nullable enable

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace IceDog.JsonDotNet.Model.NewJsonConverter
{
    public class UserConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(User);
        }

        //[return: NullableAttribute(2)]
        public override object? ReadJson(JsonReader reader, Type objectType, /*[NullableAttribute(2)]*/ object? existingValue, JsonSerializer serializer)
        {
            User user = new User
            {
                Name = reader.Value as string
            };
            return user;
        }

        public override void WriteJson(JsonWriter writer, /*[NullableAttribute(2)]*/ object? value, JsonSerializer serializer)
        {
            if (value is User user)
            {
                writer.WriteValue(user?.Name);
            }
        }
    }
}
